import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

//* 1.创建一个arraList集合,并添加以下字符串,字符串中前面是姓名 ,后面是年龄
//	 *  "zhangsn,23"
//	 *  "lisi,24"
//	 *  "wangwu,25"
//	 *  保留年龄大于24岁的,并将结果收集到map集合中,姓名为建,年龄为值
//
//		ArrayList<String> arr=new ArrayList();
//		Collections.addAll(arr, "张三,21", "李四,24", "丁真,26", "珍珠,27", "锐刻五,30");

public class Java001 {
    public static void main(String[] args) {
        ArrayList<String> arrlist= new ArrayList<>();
        Collections.addAll(arrlist, "张三,21", "李四,24", "丁真,26", "珍珠,27", "锐刻五,30");
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        Set<Map.Entry<String, Integer>> entries = map.entrySet();

        System.out.println("流式表达式");
        System.out.println("Lambda:");
        Map<String, Integer> a = arrlist.stream().collect(Collectors.toMap(s -> s.split(",")[0], s -> Integer.parseInt(s.split(",")[1])));

        System.out.println(a);

        System.out.println("不用Lambda");
        a=arrlist.stream().collect(Collectors
                .toMap(new Function<String, String>() {
                            @Override
                            public String apply(String s) {
                                return s.split(",")[0];
                            }
                            },
                        new Function<String, Integer>() {
                            @Override
                            public Integer apply(String s) {
                                return Integer.parseInt(s.split(",")[1]);
                            }
                        }));
        System.out.println(a);

        System.out.println("=======");
        System.out.println("引用:");


        arrlist.stream().map(Java001::fun).forEach(System.out::println);

    }
    public static HashMap<String,Integer> fun(String s){
        HashMap<String,Integer> map1= new HashMap<>();
        map1.put(s.split(",")[0],
                Integer.parseInt(s.split(",")[1]));
        return map1;
    }
}
